%testCase for triangle data
%varfication of GPA
% allTriShape = generateRandomTriganleTranslateOnly(100);
% plotAllShapeLine(allTriShape,100);
% allTriPreShape = AllPreShape(allTriShape);
% allTriGPAShape = GPA(allTriPreShape);
% plotAllShapeLine(allTriGPAShape,100);
%[V lambda] = PCA(allTriGPAShape);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%TestCase Triangle
% allTriShape = generateRandomTriganle(100);
% plotAllShapeLine(allTriShape,100);
% allTriPreShape = AllPreShape(allTriShape);
% [allTriGPAShape estShape] = GPA(allTriPreShape);
% plotAllShapeLine(allTriGPAShape,100);
% [V lambda] = PCA(allTriGPAShape);
% %draw mean shape
% drawSingleShape(estShape,'b');
% %plot eignvalue
% bar(lambda(100:-1:90));
% %Plot variation at 2 mode
% %mode 1
% plotMode(estShape, V, lambda, 100);
% %mode 2
% plotMode(estShape, V, lambda, 99);
% %mode 3
% plotMode(estShape, V, lambda, 98);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear; clc;
%testCase for the Corpus callosum shape
headerName = 'cc.';
tailName = '.lpts';
N = 32;
n = 64;
path = 'cc-shapes/';

%store all shape in a 3D matrix===========================================
allShape = zeros(2,n,N);

for i=0:(N-1)
    filename = strcat(headerName, strcat(sprintf('%02d',i),tailName));
    allShape(:,:,i+1) = loadShapeFromFile(strcat(path,filename));
end

%plot all point in all shape==============================================
figure;plotAllShape(allShape, N);

%preshape is the normalized shape without rotation aligment
%get preShape=============================================================
allpreShape = AllPreShape(allShape);

%OPA======================================================================
allOPAShape = zeros(2,n,N);
refShape = allpreShape(:,:,1);
for i=1:N
    allOPAShape(:,:,i) = rotateToRefShape(allpreShape(:,:,i), refShape);
end
figure;plotAllShape(allOPAShape, N);

%GPA======================================================================
[allGPAShape estShape] = GPA(allpreShape);%zeros(2,n,N);
figure;plotAllShape(allGPAShape, N);
%draw mean shape
drawSingleShapeScatter(estShape,'b');
%PCA for shape estimation=================================================
[V lambda] = PCA_notrick(allGPAShape);
%plot eignvalue
figure;bar(lambda(2*n:-1:2*n-10));
%shape reconstruct, meanshape is the estShape
%mode 1
plotModeScatter(estShape, V, lambda, n, 2*n);
%mode 2
plotModeScatter(estShape, V, lambda, n, 2*n-1);
%mode 3
plotModeScatter(estShape, V, lambda, n, 2*n-2);
%mode 4
plotModeScatter(estShape, V, lambda, n, 2*n-3);

